﻿using Microsoft.AspNetCore.Mvc;
using MVC系统mvc.Dto.Bom;
using MVC系统mvc.Dto.IngredientDto;
using MVC系统mvc.Dto.Process;
using MVC系统mvc.Dto.Quality;
using MVC系统mvc.Dto.RawMater;
using Newtonsoft.Json;
using NuGet.Common;
using System.Reflection;
using WMS_MAV;

namespace MVC系统mvc.Controllers
{
    public class BomController : Controller
    {
        private readonly IConfiguration _configuration;

        public BomController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// bOM添加
        /// </summary>
        /// <returns></returns>
        public IActionResult BomAdd()
        {
            return View();
        }
        /// <summary>
        /// bOM显示
        /// </summary>
        /// <returns></returns>
        public IActionResult BomIndex()
        {
            return View();
        }
        /// <summary>
        /// 添加Bom
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> AddBom(AddBom model)
        {
            HttpClientWrapper client = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "bom/api/Bom/AddBom";
            string list = JsonConvert.SerializeObject(model);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// Bom显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> BomShow(BomDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "bom/api/Bom/Show?Pageindex="+model.Pageindex+"&Pagesize="+model.Pagesize+"&Bombh="+model.Bombh+"&Chenbh="+model.Chenbh;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// Bom里面原料显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> IngredientShow(IngredientShowDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "yuan/api/Ingredient/Show?Pageindex=" + model.Pageindex + "&Pagesize=" + model.Pagesize + "&Ingredientnumber=" + model.Ingredientnumber + "&IngredientName=" + model.IngredientName + "&State=" + model.State;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// Bom里面工艺显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> ProcessList(ListProcessDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);

            string url = _configuration["Url"] + "ppapi/api/ProcessRoute/GetProcessRouteList?ProcessPouteNumber=" + model.ProcessPouteNumber + "&ProcessRouteName="+ model.ProcessRouteName + "&State=" + model.State + "&PageIndex=" + model.PageIndex + "&PageSize=" + model.PageSize;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        ///单删
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDeleteRaw(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "bom/api/Bom/DelBom";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// bOM修改
        /// </summary>
        /// <returns></returns>
        public IActionResult BomUpdate()
        {
            return View();
        }
        /// <summary>
        /// Bom反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> BomBackfill(BomBackfillBomDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "bom/api/Bom/BackfillBom?Bombh="+model.Bombh;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 取原料id
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> BomYuna(BomBackfillBomDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "bom/api/Bom/BackfillYuan?Bombh=" + model.Bombh;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// Bom原料反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> YuanBackfill(BomYuanDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "bom/api/Ingredient/BackfillBom";
            string list = JsonConvert.SerializeObject(model.IngredientId);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);

        }
        /// <summary>
        /// 工艺反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> BomGong(GongyiDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "ppapi/api/ProcessRoute/BackGong?ProcessRouteId="+model.ProcessRouteId;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }

        /// <summary>
        /// Bom修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> BomUpdate(AddBom obj1)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(obj1.token);
            string url = _configuration["Url"] + "bom/api/Bom/UpdateBom";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await httpClientWrapper.PostAsync(url, list);
            return Json(response);
        }


    }
}
